package zzj.campus_book_sharing_platform.Aigc.controller;

import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import zzj.campus_book_sharing_platform.Aigc.Service.AigcService;
import zzj.campus_book_sharing_platform.domain.dto.AiQuestion;
import zzj.campus_book_sharing_platform.uitl.ResultFormat;
import zzj.campus_book_sharing_platform.uitl.ResultUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
@RequestMapping("/Ai")
@Tag(name = "AI服务")
public class AigcController {

    @Resource
    AigcService aigcService;

    @Operation(summary = "AI对话")
    @RequestMapping(value = "/test",method = RequestMethod.POST)
    public ResultFormat AI(@RequestBody AiQuestion Question, HttpSession session) throws NoApiKeyException, InputRequiredException, IOException {
        return aigcService.getAnswer(Question,session);
    }

    @Operation(summary = "AI历史对话")
    @RequestMapping(value = "/hisData",method = RequestMethod.GET)
    public ResultFormat getHIstoryData(HttpSession session){
        String userId = String.valueOf(session.getAttribute("userId"));
        //查询前10条问答数据
        return aigcService.selectStateByUserId(userId);
    }
}
